<import template="/panel/_header" />
<div class="page-container">
    <div class="main-content">
        <div class="page-title">

            <div class="title-env">
                <h1 class="title">自定义加密方式</h1>
                <p class="description">自定义节点加密方式，仅对允许自定义节点有效</p>
            </div>

            <div class="breadcrumb-env">
                <ol class="breadcrumb bc-1">
                    <li>
                        <a href="/member"><i class="fa-home"></i>主页</a>
                    </li>
                    <li>
                        <a href="javascript:;">自定义信息</a>
                    </li>
                    <li class="active">
                        <strong>自定义加密</strong>
                    </li>
                </ol>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="fa fa-angle-right"></i>&nbsp;修改自定义加密方式
                    </div>
                    <div class="panel-body">
                        <div class="form-group">
                            <label for="method-old" class="control-label">原加密方式：</label>
                            <input type="text" class="form-control disabled" id="method-old" value="{$user->method}" disabled="disabled">
                            <label for="method-new" class="control-label">新加密方式：</label>
                            <select class="form-control" id="method-new" data-value="">
                                <option value="-1">不使用自定义加密</option>
                                <option value="rc4-md5">rc4-md5</option>
                                <option value="aes-256-cfb">aes-256-cfb</option>
                                <option value="aes-192-cfb">aes-192-cfb</option>
                                <option value="aes-128-cfb">aes-128-cfb</option>
                                <option value="chacha20">chacha20</option>
                            </select>
                        </div>
                    </div>
                    <button class="btn btn-info btn-block" id="submit-method">确定修改</button>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="fa fa-angle-right"></i>&nbsp;当前支持自定义加密的节点
                    </div>
                    <div class="panel-body">
                        <div class="form-group">
                            <if condition="count($nodeList)>0"><loop variable="$nodeList" key="$key" value="$node"><i class="fa fa-server" aria-hidden="true"></i> &nbsp; {$node->name}<br/></loop><else>无</if>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
            $(document).ready(function(){
                var method = '{$user->method}';
                if(method) {
                    $("#method-new").val(method);
                } else {
                    $("#method-new").val('-1');
                    $("#method-old").val('不使用自定义加密');
                }

                $("#submit-method").click(function(){
                    var but = $(this);
                    var method_new = $("#method-new").val();
                    if(method_new == null || method_new == '') {
                        showToastr("你不填写就想改真的好吗?", 0, 2000);
                        return;
                    }
                    but.attr('disabled', 'true').addClass('disabled');
                    $.ajax({
                        type:"POST",
                        url:"/member/changeMethod.json",
                        data:{method:$("#method-new").val()},
                        dataType:"json",
                        success:function(result){
                            but.removeAttr('disabled').removeClass('disabled');
                            if(result.code != 200) {
                                showToastr(result.message, 0);
                                return;
                            }
                            showToastr(result.data.message, 0);
                            if($("#method-new").val() == '-1') {
                                $("#method-old").val('不使用自定义加密');
                            } else {
                                $("#method-old").val($("#method-new").val());
                            }
                        },
                        error:function(jqXHR){
                            showToastr("发生错误："+jqXHR.status, 0);
                            but.removeAttr('disabled').removeClass('disabled');
                        }
                    })
                });
            });
        </script>
        <import template="/panel/_copyright" />
    </div>
</div>
<import template="/panel/_footer" />